<?php
namespace app\common\model;
class Chat extends Base{
    protected $pk = 'chat_id';
    
    //关注的人的动态
    public function follows($userId, $sort = 'DESC') {
        $sort = strtoupper($sort);
        $this->paginate();
        $where = 'b.user_id=' . $userId;
        if($this->lastPkId > 0){
            if($sort === 'DESC'){
                $where .= ' AND a.chat_id <' . $this->lastPkId;
            }else{
                $where .= ' AND a.chat_id >' . $this->lastPkId;
            }
        }
        
        $list = $this
        ->alias('a')
        ->join('__FOLLOW_USER__ b', 'a.user_id=b.follow_user_id')
        ->where($where)
        ->field('a.chat_id, a.user_id, a.content, a.picture, a.chat_type, a.create_time')
        ->order('chat_id ' . $sort)
        ->limit($this->pageOffset, $this->pageSize)
        ->select()
        ->toArray();
        
        return ['list' => $list];
    }
    
}